package org.jeecg.modules.settle.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.cmbCloudDirectLink.utils.CMBApi;
import org.jeecg.common.api.dto.BankSetDTO;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.LimitSubmit;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.*;
import org.jeecg.common.util.oss.OssBootUtil;
import org.jeecg.modules.api.IManageBaseAPI;
import org.jeecg.modules.business.service.ICaishuiBusinessService;
import org.jeecg.modules.business.service.ICaishuiCompanySetService;
import org.jeecg.modules.finance.service.ICaishuiRefundRecordService;
import org.jeecg.modules.manage.entity.CaishuiBusiness;
import org.jeecg.modules.manage.entity.CaishuiRefundRecord;
import org.jeecg.modules.manage.entity.CaishuiTaskSettle;
import org.jeecg.modules.manage.entity.CaishuiTaskSettleItem;
import org.jeecg.modules.manage.vo.CaishuiTaskSettlePage;
import org.jeecg.modules.manage.vo.TaskSettleImportVo;
import org.jeecg.modules.settle.service.ICaishuiTaskSettleItemService;
import org.jeecg.modules.settle.service.ICaishuiTaskSettleService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

/**
 * @Description: 任务结算[B端]
 * @Author: yfkj
 * @Date: 2023-02-20
 * @Version: V1.0
 */
@Api(tags = "任务结算[B端]")
@RestController
@RequestMapping("/settle/caishuiTaskSettle")
@Slf4j
public class CaishuiTaskSettleController {

    @Value(value = "${jeecg.path.upload}")
    private String uploadpath;

    /**
     * 本地：local minio：minio 阿里：alioss
     */
    @Value(value = "${jeecg.uploadType}")
    private String uploadType;

    @Autowired
    private ICaishuiTaskSettleService caishuiTaskSettleService;
    @Autowired
    private ICaishuiTaskSettleItemService caishuiTaskSettleItemService;
    @Autowired
    private ICaishuiBusinessService iCaishuiBusinessService;
    @Autowired
    private ICaishuiRefundRecordService iCaishuiRefundRecordService;
    @Autowired
    private ICaishuiCompanySetService iCaishuiCompanySetService;
    //注入feign客户端
    @Resource
    private IManageBaseAPI iManageBaseAPI;
    @Resource
    private ISysBaseAPI iSysBaseAPI;
    @Autowired
    private RedisUtil redisUtil;



    /**
     * 分页列表查询
     *
     * @param caishuiTaskSettle
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "任务结算[B端]-分页列表查询", notes = "任务结算[B端]-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<CaishuiTaskSettle>> queryPageList(CaishuiTaskSettle caishuiTaskSettle,
                                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                          HttpServletRequest req) {
        QueryWrapper<CaishuiTaskSettle> queryWrapper = QueryGenerator.initQueryWrapper(caishuiTaskSettle, req.getParameterMap());
        queryWrapper.lambda().eq(CaishuiTaskSettle::getBusinessId, TokenUtils.getLoginUser().getCurBusiness());
        queryWrapper.lambda().eq(CaishuiTaskSettle::getCompanyId, TokenUtils.getLoginUser().getCurCompany());
        Page<CaishuiTaskSettle> page = new Page<CaishuiTaskSettle>(pageNo, pageSize);
        IPage<CaishuiTaskSettle> pageList = caishuiTaskSettleService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 分页列表查询任务结算详情
     *
     * @param caishuiTaskSettleItem
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "任务结算[B端]-分页列表查询任务结算详情", notes = "任务结算[B端]-分页列表查询任务结算详情")
    @GetMapping(value = "/itemList")
    public Result<IPage<CaishuiTaskSettleItem>> queryPageitemList(CaishuiTaskSettleItem caishuiTaskSettleItem,
                                                                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                  HttpServletRequest req) {
        QueryWrapper<CaishuiTaskSettleItem> queryWrapper = QueryGenerator.initQueryWrapper(caishuiTaskSettleItem, req.getParameterMap());
        Page<CaishuiTaskSettleItem> page = new Page<CaishuiTaskSettleItem>(pageNo, pageSize);
        IPage<CaishuiTaskSettleItem> pageList = caishuiTaskSettleItemService.page(page, queryWrapper);
        return Result.OK(pageList);
    }


//    /**
//     * 添加
//     *
//     * @param caishuiTaskSettlePage
//     * @return
//     */
//    @AutoLog(value = "任务结算[B端]-添加", terminal = 2)
//    @ApiOperation(value = "任务结算[B端]-添加", notes = "任务结算[B端]-添加")
//    @PostMapping(value = "/add")
//    public Result<String> add(@RequestBody CaishuiTaskSettlePage caishuiTaskSettlePage) {
//        CaishuiTaskSettle caishuiTaskSettle = new CaishuiTaskSettle();
//        BeanUtils.copyProperties(caishuiTaskSettlePage, caishuiTaskSettle);
//        caishuiTaskSettleService.saveMain(caishuiTaskSettle, caishuiTaskSettlePage.getCaishuiTaskSettleItemList());
//        return Result.OK("添加成功！");
//    }

//    /**
//     * 编辑
//     *
//     * @param caishuiTaskSettlePage
//     * @return
//     */
//    @AutoLog(value = "任务结算[B端]-编辑", dataType = 2, terminal = 2)
//    @ApiOperation(value = "任务结算[B端]-编辑", notes = "任务结算[B端]-编辑")
//    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
//    public Result<String> edit(@RequestBody CaishuiTaskSettlePage caishuiTaskSettlePage) {
//        CaishuiTaskSettle caishuiTaskSettle = new CaishuiTaskSettle();
//        BeanUtils.copyProperties(caishuiTaskSettlePage, caishuiTaskSettle);
//        CaishuiTaskSettle caishuiTaskSettleEntity = caishuiTaskSettleService.getById(caishuiTaskSettle.getId());
//        if (caishuiTaskSettleEntity == null) {
//            return Result.error("未找到对应数据");
//        }
//        caishuiTaskSettleService.updateMain(caishuiTaskSettle, caishuiTaskSettlePage.getCaishuiTaskSettleItemList());
//        return Result.OK("编辑成功!");
//    }

    /**
     * 提交、作废操作
     *
     * @param id
     * @param status
     * @return
     */
    @AutoLog(value = "任务结算[B端]-提交、作废操作", terminal = 2)
    @ApiOperation(value = "任务结算[B端]-提交、作废操作", notes = "任务结算[B端]-提交、作废操作")
    @GetMapping(value = "/statusOne")
    @LimitSubmit(key = "business:taskSettle:statusOne:%bId:%cId", spelKey = "#id")
    public Result<?> statusOne(@RequestParam(name = "id", required = true) String id,
                               @RequestParam(name = "captcha", required = false) String captcha,
                               @RequestParam(name = "status", required = true) int status) {
        /**作废*/
        if(status == 4){
            UpdateWrapper<CaishuiTaskSettle> updateWrapper = new UpdateWrapper<CaishuiTaskSettle>();
            updateWrapper.lambda().set(CaishuiTaskSettle::getStatus,4);
            updateWrapper.lambda().set(CaishuiTaskSettle::getExtendStatus,3);
            updateWrapper.lambda().set(CaishuiTaskSettle::getSubmitTime,new Date());
            updateWrapper.lambda().eq(CaishuiTaskSettle::getId,id);
            caishuiTaskSettleService.update(new CaishuiTaskSettle(),updateWrapper);
        }
        /**提交*/
        if(status==1){
            //节假日、周末、晚上9点以后禁止下发
            boolean b = false;//是否限制下发
            int start_hh = 0;//每日下发开始时间
            int end_hh = 0;//每日下发结束时间
            List<Map<String, Object>> mapList = iSysBaseAPI.queryListBySupCode("A04");
            if (oConvertUtils.listIsNotEmpty(mapList)) {
                for (Map<String, Object> map : mapList) {
                    if (map.get("code").equals("A04B01")) {
                        if (map.get("value").equals("1")) {
                            b = true;
                        }
                    } else if (map.get("code").equals("A04B02")) {
                        start_hh = oConvertUtils.getInt(map.get("value"), 0);
                    } else if (map.get("code").equals("A04B03")) {
                        end_hh = oConvertUtils.getInt(map.get("value"), 0);
                    }
                }
            }
            if (b) {
                int hh = oConvertUtils.getInt(DateUtils.HH.format(new Date()), 0);
                if (end_hh <= 0) {
                    if (hh < start_hh) {
                        return Result.error(start_hh + "点之前禁止下发！");
                    }
                } else {
                    if (hh < start_hh || hh >= end_hh) {
                        return Result.error(start_hh + "点之前和" + end_hh+ "之后禁止下发！");
                    }
                }
                //判断指定是工作日 周末 还是节假日，0 上班 1周末 2节假日
                try {
                    String request = HolidayUtils.request(DateUtils.sdf8.format(new Date()));
                    if (oConvertUtils.isNotEmpty(request)) {
                        int isWork = oConvertUtils.getInt(request.trim());
                        if (isWork > 0) {
                            return Result.error("节假日或周末禁止下发！");
                        }
                    }
                } catch (Exception e) {
                    log.error("判断指定是工作日出错：",e.getMessage());
                }
            }

            //从缓存中获取手机验证码
            Object code = redisUtil.get(CommonConstant.PHONE_REDIS_KEY_PRE + TokenUtils.getLoginUser().getUsername());
            if (oConvertUtils.isEmpty(code)) {
                return Result.error("短信验证码已失效！");
            } else if (!captcha.equals(code)) {
                return Result.error("短信验证码错误！");
            }

            //任务结算信息
            CaishuiTaskSettle caishuiTaskSettle = caishuiTaskSettleService.getById(id);
            if (oConvertUtils.isEmpty(caishuiTaskSettle)) {
                return Result.error("任务结算信息错误！");
            }else if(caishuiTaskSettle.getStatus()!=0){
                return Result.error("任务结算信息错误！");
            }

            //账户余额
            double accountBalance = 0.00;
            BankSetDTO bankSetDTO = iCaishuiCompanySetService.queryCompanySet(caishuiTaskSettle.getPayAccount());
            Result b_result = CMBApi.querySubUnitBalance(caishuiTaskSettle.getPayAccount(),caishuiTaskSettle.getPaySubUnit(), bankSetDTO);
            if(b_result.isSuccess()){
                accountBalance = oConvertUtils.getDouble(b_result.getResult().toString(),0.00);
            }
            double totalAmount = caishuiTaskSettle.getTotalAmount().add(BigDecimal.valueOf(caishuiTaskSettle.getServiceFee())).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
            if (totalAmount <= 0) return Result.error("结算金额错误！");
            if (totalAmount > accountBalance) return Result.error("账户余额不足！");

            if(caishuiTaskSettle.getSubmitStatus()==3){
                return Result.error("禁止下发！");
            }else if(caishuiTaskSettle.getSubmitStatus()==2){
                caishuiTaskSettle.setStatus(1);
                caishuiTaskSettle.setSubmitTime(new Date());
                caishuiTaskSettleService.updateById(caishuiTaskSettle);
                return Result.OK("提交成功，请耐心等待审核!");
            }else if(caishuiTaskSettle.getSubmitStatus()==1){
                //下发
                caishuiTaskSettle.setSubmitTime(new Date());
                return iManageBaseAPI.doIssuedSalary(caishuiTaskSettle);
            }else {
                return Result.error("操作失败！");
            }
        }
        return Result.OK("操作成功!");
    }

//    /**
//     * 通过id删除
//     *
//     * @param id
//     * @return
//     */
//    @AutoLog(value = "任务结算[B端]-通过id删除", terminal = 2)
//    @ApiOperation(value = "任务结算[B端]-通过id删除", notes = "任务结算[B端]-通过id删除")
//    @DeleteMapping(value = "/delete")
//    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
//        caishuiTaskSettleService.delMain(id);
//        return Result.OK("删除成功!");
//    }

//    /**
//     * 批量删除
//     *
//     * @param ids
//     * @return
//     */
//    @AutoLog(value = "任务结算[B端]-批量删除", terminal = 2)
//    @ApiOperation(value = "任务结算[B端]-批量删除", notes = "任务结算[B端]-批量删除")
//    @DeleteMapping(value = "/deleteBatch")
//    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
//        this.caishuiTaskSettleService.delBatchMain(Arrays.asList(ids.split(",")));
//        return Result.OK("批量删除成功！");
//    }

//    /**
//     * 通过id查询
//     *
//     * @param id
//     * @return
//     */
//    @ApiOperation(value = "任务结算[B端]-通过id查询", notes = "任务结算[B端]-通过id查询")
//    @GetMapping(value = "/queryById")
//    public Result<CaishuiTaskSettle> queryById(@RequestParam(name = "id", required = true) String id) {
//        CaishuiTaskSettle caishuiTaskSettle = caishuiTaskSettleService.getById(id);
//        if (caishuiTaskSettle == null) {
//            return Result.error("未找到对应数据");
//        }
//        return Result.OK(caishuiTaskSettle);
//
//    }

    /**
     * 通过主表ID查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "任务结算[B端]-通过主表ID查询", notes = "任务结算[B端]-通过主表ID查询")
    @GetMapping(value = "/queryCaishuiTaskSettleItemByMainId")
    public Result<IPage<CaishuiTaskSettleItem>> queryCaishuiTaskSettleItemListByMainId(@RequestParam(name = "id", required = true) String id) {
        List<CaishuiTaskSettleItem> caishuiTaskSettleItemList = caishuiTaskSettleItemService.selectByMainId(id);
        IPage<CaishuiTaskSettleItem> page = new Page<>();
        page.setRecords(caishuiTaskSettleItemList);
        page.setTotal(caishuiTaskSettleItemList.size());
        return Result.OK(page);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param caishuiTaskSettle
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, CaishuiTaskSettle caishuiTaskSettle) {
        // Step.1 组装查询条件查询数据
        QueryWrapper<CaishuiTaskSettle> queryWrapper = QueryGenerator.initQueryWrapper(caishuiTaskSettle, request.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        queryWrapper.lambda().eq(CaishuiTaskSettle::getBusinessId, sysUser.getCurBusiness());
        queryWrapper.lambda().eq(CaishuiTaskSettle::getCompanyId, sysUser.getCurCompany());

        //配置选中数据查询条件
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            queryWrapper.in("id", selectionList);
        }
        //Step.2 获取导出数据
        List<CaishuiTaskSettle> caishuiTaskSettleList = caishuiTaskSettleService.list(queryWrapper);

        // Step.3 组装pageList
        List<CaishuiTaskSettlePage> pageList = new ArrayList<CaishuiTaskSettlePage>();
        for (CaishuiTaskSettle main : caishuiTaskSettleList) {
            CaishuiTaskSettlePage vo = new CaishuiTaskSettlePage();
            BeanUtils.copyProperties(main, vo);
            List<CaishuiTaskSettleItem> caishuiTaskSettleItemList = caishuiTaskSettleItemService.selectByMainId(main.getId());
            vo.setCaishuiTaskSettleItemList(caishuiTaskSettleItemList);
            pageList.add(vo);
        }

        // Step.4 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        mv.addObject(NormalExcelConstants.FILE_NAME, "任务结算[B端]列表");
        mv.addObject(NormalExcelConstants.CLASS, CaishuiTaskSettlePage.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("任务结算[B端]数据", "导出人：" + sysUser.getRealname(), "任务结算[B端]"));
        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
        return mv;
    }


    /**
     * 查询当前商户相关信息
     * @return
     */
    @GetMapping(value = "/queryBusinessInfo")
    public Result<?> queryBusinessInfo() {
        CaishuiBusiness business = iCaishuiBusinessService.getOne(new LambdaQueryWrapper<CaishuiBusiness>()
                .select(CaishuiBusiness::getCheckAmount,CaishuiBusiness::getStopAmount,CaishuiBusiness::getLowestAmount)
                .eq(CaishuiBusiness::getId,TokenUtils.getLoginUser().getCurBusiness()));
        return Result.OK(business);
    }

    /**
     * 结算单导入
     *
     * @param request
     * @return
     */
    @AutoLog(value = "任务结算[B端]-结算单导入", terminal = 2)
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request) throws IOException {
        return caishuiTaskSettleService.importExcel(request, uploadType);
    }

    /**
     * 导入数据列表
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/handleImportExcel", method = RequestMethod.POST)
    public Result<?> handleImportExcel(HttpServletRequest request) {
        Map<String, Object> result = new HashMap<>();
        List<TaskSettleImportVo> list = new ArrayList<>();
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            // 获取上传文件对象
            MultipartFile file = entity.getValue();
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<TaskSettleImportVo> importVoList = ExcelImportUtil.importExcel(file.getInputStream(), TaskSettleImportVo.class, params);
                //按照编码长度排序
//                Collections.sort(importVoList);
                list.addAll(importVoList);

                /**上传结算单到服务器*/
                String savePath = fileUpload(file,TokenUtils.getLoginUser().getCurBusiness(),uploadType);
                if(oConvertUtils.isEmpty(savePath)){
                    return Result.error("上传文件发生错误！");
                }
                result.put("savePath", savePath);
                result.put("fileName", file.getOriginalFilename());
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("导入数据错误!");
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        result.put("taskSettleItemList", list);
        return Result.ok(result);
    }

    /**
     * 处理导入任务结算数据
     *
     * @param jsonObject
     * @return
     */
    @AutoLog(value = "任务结算[B端]-批量导入任务结算数据", terminal = 2)
    @PostMapping(value = "/handleImportList")
    @LimitSubmit(key = "business:taskSettle:handleImportList:%bId:%cId")
    public Result<?> handleImportList(@RequestBody JSONObject jsonObject) throws IOException {
        //当前登录用户
        LoginUser loginUser = TokenUtils.getLoginUser();
        String fileName = jsonObject.getString("fileName");//文件名
        String savePath = jsonObject.getString("savePath");//文件保存路径
        JSONArray jsonArray = jsonObject.getJSONArray("taskSettleItemList");
        if (oConvertUtils.isEmpty(fileName) || oConvertUtils.isEmpty(savePath) || oConvertUtils.listIsEmpty(jsonArray)) {
            return Result.error("请上传结算单数据！");
        } else if(jsonArray.size() > 1000){
            return Result.error("单批次导入数据不能超过1000条！");
        }

        //判断是否存在发放中的数据
        CaishuiTaskSettle taskSettle = caishuiTaskSettleService.getOne(new LambdaQueryWrapper<CaishuiTaskSettle>()
                .select(CaishuiTaskSettle::getStatus,CaishuiTaskSettle::getExtendStatus)
                .eq(CaishuiTaskSettle::getBusinessId,loginUser.getCurBusiness()).eq(CaishuiTaskSettle::getCompanyId,loginUser.getCurCompany())
                .orderByDesc(CaishuiTaskSettle::getCreateTime).last("LIMIT 1"));
        if (oConvertUtils.isNotEmpty(taskSettle) && oConvertUtils.isNotEmpty(taskSettle.getStatus())
                && oConvertUtils.isNotEmpty(taskSettle.getExtendStatus())){
            if (taskSettle.getStatus()==0) return Result.error("请先操作完成上一笔【任务结算】订单！");
            if (taskSettle.getStatus()==1) return Result.error("请耐心等待上一笔【任务结算】订单审核完成！");
            if (taskSettle.getStatus()==2) {
                if (taskSettle.getExtendStatus()==0 || taskSettle.getExtendStatus()==1
                        || taskSettle.getExtendStatus()==4) {
                    return Result.error("请耐心等待上一笔【任务结算】订单银行处理完成！");
                }
            }
        }

        //判断是否存在退款中的数据
        CaishuiRefundRecord refundRecord = iCaishuiRefundRecordService.getOne(new LambdaQueryWrapper<CaishuiRefundRecord>()
                .select(CaishuiRefundRecord::getStatus).eq(CaishuiRefundRecord::getBusinessId,loginUser.getCurBusiness())
                .eq(CaishuiRefundRecord::getCompanyId,loginUser.getCurCompany()).orderByDesc(CaishuiRefundRecord::getCreateTime)
                .last("LIMIT 1"));
        if (oConvertUtils.isNotEmpty(refundRecord) && oConvertUtils.isNotEmpty(refundRecord.getStatus())){
            if (refundRecord.getStatus()==0) return Result.error("请先操作完成上一笔【退款】订单！");
            if (refundRecord.getStatus()==1) return Result.error("请先处理完成上一笔【退款】订单！");
            if (refundRecord.getStatus()==3) return Result.error("请耐心等待上一笔【退款】订单银行处理完成！");
        }

        return Result.ok("操作成功！",caishuiTaskSettleService.handleImportList(jsonArray,fileName,savePath));
    }

    public String fileUpload(MultipartFile file, String businessId, String uploadType){
        String savePath = "";//数据库保存路径
        String bizPath = "uploadFile/taskSettle/" + businessId + "/" + DateUtils.sdf8.format(new Date());//文件的文件夹标记
        //根据配置的文件上传类型选择文件上传
        try {
            if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
//					 savePath = this.uploadLocal(file,bizPath,2);//本地文件上传
            }else if(CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)){
                savePath = MinioUtil.upload(file,bizPath,null);//minio文件上传
            }else if(CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)){
                savePath = OssBootUtil.upload(file,bizPath);//阿里云OSS文件上传
            }
        }catch (Exception e){
            log.error("文件上传失败：" + e.getMessage());
        }
        return savePath;
    }

}
